package com.liy.framework.web.rs.exception;

import com.liy.framework.common.exception.BusinessException;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;
import javax.ws.rs.NotSupportedException;

import org.springframework.dao.DuplicateKeyException;
import org.springframework.jdbc.BadSqlGrammarException;

public class ExceptionManager {

    private static final Map<String, com.liy.framework.web.rs.exception.ExceptionType> expMaps = new HashMap();
    public static final String defaultCode = "500";
    public static com.liy.framework.web.rs.exception.ExceptionType defaultExp = new com.liy.framework.web.rs.exception.ExceptionType("500", "操作失败:服务器内部错误,请联系管理员!");

    private ExceptionManager() {
    }

    public static com.liy.framework.web.rs.exception.ExceptionType get(String key) {
        return (com.liy.framework.web.rs.exception.ExceptionType)expMaps.getOrDefault(key, defaultExp);
    }

    public static com.liy.framework.web.rs.exception.ExceptionType get(Throwable exp) {
        return (com.liy.framework.web.rs.exception.ExceptionType)expMaps.getOrDefault(exp.getClass().getSimpleName(), defaultExp);
    }

    static {
        expMaps.put(SQLException.class.getSimpleName(), new com.liy.framework.web.rs.exception.ExceptionType("500", "操作失败:脚本执行异常!"));
        expMaps.put(BadSqlGrammarException.class.getSimpleName(), new com.liy.framework.web.rs.exception.ExceptionType("500", "操作失败:脚本执行异常!"));
        expMaps.put(BusinessException.class.getSimpleName(), new com.liy.framework.web.rs.exception.ExceptionType("500", "操作失败:业务处理异常!"));
        expMaps.put(NotSupportedException.class.getSimpleName(), new com.liy.framework.web.rs.exception.ExceptionType("500", "操作失败:不支持的请求!"));
        expMaps.put(DuplicateKeyException.class.getSimpleName(), new com.liy.framework.web.rs.exception.ExceptionType("500", "操作失败:违反唯一约束条件!"));
    }
}
